package com.cs.beneficios.web.action;

import com.cs.beneficios.business.entity.CargueDAO;
import com.cs.beneficios.common.ConnectionFactory;
import com.cs.beneficios.web.form.StrutsUploadForm;
//import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;


/**
 * Struts File Upload Action Form.
 *
*/
public class StrutsUploadAction extends Action
{
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    
    StrutsUploadForm myForm = (StrutsUploadForm)form;

    // Process the FormFile
    FormFile myFile = myForm.getTheFile();
    String contentType = myFile.getContentType();
    String fileName    = myFile.getFileName();
    int fileSize       = myFile.getFileSize();
    byte[] fileData    = myFile.getFileData();
    /*System.out.println("contentType: " + contentType);
    System.out.println("File Name: " + fileName);
    System.out.println("File Size: " + fileSize);*/

      //ConnectionFactory cf = new ConnectionFactory("beneficios","beneficios");
	  ConnectionFactory cf = new ConnectionFactory();
      CargueDAO cargue = new CargueDAO(cf);
      int icargue = cargue.uploadFile(134,fileData);
    
      return mapping.findForward("success");
  }
} 